element_type& operator[](size_t i) const; // only defined in array-specialization
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// unique_ptr::operator[]
#include <iostream>
#include <memory>
int main () {
std::unique_ptr<int[]> foo (new int[5]);
for (int i=0; i<5; ++i) foo[i] = i;
for (int i=0; i<5; ++i) std::cout << foo[i] << ' ';
std::cout << '\n';
return 0;
}
0 1 2 3 4